<?php
    namespace app\admin\model;
    use think\Model;
    use think\request;
    use think\Db;

    
    class Course extends Model
    {

        public function course_list(){
            $map =[];
            //$map['Singer_Id'] = array('eq',2);
            $request = Request::instance();
            $data = $this->where($map)->order('Course_id asc')->select();
            return $data;
        }

        public function coursen_list(){
            $map =[];
            //$map['Singer_Id'] = array('eq',2);
            $request = Request::instance();
            $coursendata = $this->where($map)->field('Course_name')->select();
            return $coursendata;
        }

        public function change_coursen_list(){
            $map =[];
            //$map['Singer_Id'] = array('eq',2);
            $request = Request::instance();
            $change_coursendata = $this->where($map)->field('Course_name')->select();
            return $change_coursendata;
        }

        public function insert($data){
            $courseno = $data['Courseno'];
            $coursename = $data['Coursename'];
            $class = $data['Class'];
            $teacher = $data['Teacher'];

            $result = Db::table('course')->insert([
                'Course_no'=>$courseno,
                'Course_name'=>$coursename,
                'Course_class'=>$class,
                'Course_teacher'=>$teacher
            ]);

            if ($result) {
                return 1; //新添成功
            } else {
                return 2; //新添失败
            }
        }

        public function change($data){

            $cid = $data['c_id'];
            $courseno = $data['c_no'];
            $coursename = $data['c_name'];
            $class = $data['Class'];
            $teacher = $data['Teacher'];

            
            
            $result = Db::table('course')->where('Course_id', $cid)->Update([
                    'Course_id'=>$cid,
                    'Course_no'=>$courseno,
                    'Course_name'=>$coursename,
                    'Course_class'=>$class,
                    'Course_teacher'=>$teacher
                    
                ]);
            //返回控制器
            if ($result) {
                return 1; //更新成功返回1
            } else {
                return 2; //更新失败返回2
            }
        }


    }
?>